package php.code.functions;

import com.google.common.base.Joiner;
import utils.titles.Title;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by thormentor on 08-04-2014.
 */
public enum TextLayout {
    INLINE("%s(%s)", ", "),
    MULTILINE("%s(\n%s\n%s)", ",\n");

    private final String pattern;
    private final Joiner joiner;

    TextLayout(String pattern, String separator) {
        this.pattern = pattern;
        this.joiner = Joiner.on(separator).skipNulls();
    }

    public String format(Function function, List<String> lines) {
        return String.format(
                pattern,
                Title.fromObject(function).toSnakeCase(),
                joiner.join(lines.stream()
                                .map(line -> function.getIndentation() + line)
                                .collect(Collectors.toList())
                ),
                function.getIndentation()
        );
    }
}
